package uk.ac.cam.cl.projectcharlie2010.game;

import ch.nostromo.tiffanys.engines.EngineResult;
import ch.nostromo.tiffanys.game.move.Move;

public class GameControllerResult {
  Move selectedMove;
  Move[] calculatedMoves;
  EngineResult engineResult;
  String previousFen;

  public GameControllerResult(Move selectedMove, Move[] calculatedMoves, EngineResult engineResult, String previousFen) {
    this.selectedMove = selectedMove;
    this.calculatedMoves = calculatedMoves;
    this.engineResult = engineResult;
    this.previousFen = previousFen;
  }

  public Move[] getCalculatedMoves() {
    return calculatedMoves;
  }

  public Move getSelectedMove() {
    return selectedMove;
  }

  public boolean isOpeningMove() {
    return engineResult.isOpeningMove();
  }

  public String getEngineStatsOneLine() {

    if (engineResult.isOpeningMove()) {
      double ms = engineResult.getTime();
      String result = "";
      result += "Depth=OB Time=" + ms/1000;
      result += " Move=" + selectedMove.getSanDescription();     
      return result;
    } else {

      double ms = engineResult.getTime();

      int evSec = (int) ((engineResult.getPositionsEvaluated()) / ms * 1000);

      String result = "";

      result += "Depth=" + this.engineResult.getDepth();
      result += " Time=" + ms / 1000;
      result += " Move=" + selectedMove.getSanDescription();     
      result += " Score=" + selectedMove.getScore();
      result += " Nodes=" + engineResult.getNodes();
      result += " ABCuts=" + engineResult.getAbCutOffs();
      result += " PosEval=" +  + engineResult.getPositionsEvaluated() + "(" + evSec + ")";
      
      return result;
    }

  }
  
  public String getEngineStatsFull() {

    if (engineResult.isOpeningMove()) {
      double ms = engineResult.getTime();

      
      String result = "";

      
      result += "Opening book: " + engineResult.getOpeningLine() + "\n";
      result += "Total time in sec: " + ms / 1000 + "\n";
      
      return result;
    } else {

      double ms = engineResult.getTime();

      int evSec = (int) ((engineResult.getPositionsEvaluated()) / ms * 1000);

      String result = "";

      result += "Search depth: " + this.engineResult.getDepth() + "\n";
      result += "Legal moves evaluated: " + this.calculatedMoves.length + "\n";
      result += "Total time in sec: " + ms / 1000 + "\n";
      result += "Nodes searched: " + engineResult.getNodes() + "\n";
      result += "AB Cuts: " + engineResult.getAbCutOffs() + "\n";
      result += "Positions evaluated: " + engineResult.getPositionsEvaluated() + " (" + evSec + " P/S) \n";

      if (engineResult.getEngineInfo() != null && engineResult.getEngineInfo().length() > 0) {
        result += engineResult.getEngineInfo();
      }

      return result;
    }
  }

public String getPreviousFEN() {
	return previousFen;
}

}
